<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>授权回调界面</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="application/javascript"></script>
    <script type="application/javascript">
        (function ($) {
            /**
             * 获得 URL 的指定参数的值
             *
             * @param name 参数名
             * @returns 参数值
             */
            $.getUrlParam = function (name) {
                const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                const r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
        })(jQuery);
    </script>
    <script type="application/javascript">
        $(function (){
            // 当界面加载的时候获取请求参数中的授权码
            const code = $.getUrlParam("code");
            // 判断是否获取得到了授权码
            if (!code){
                alert('获取不到 code 参数，请排查！')
                return;
            }
            // 提交
            const  redirectUri = "http://127.0.0.1:19090/callback.html"
            $.ajax({
                url:"http://127.0.0.1:19090/auth/login-by-code?code=" + code + "&redirectUri=" + redirectUri,
                method:'POST',
                success:function (resp){
                    if(resp.code !== 0){
                        alert('获得访问令牌失败，原因：' + result.msg)
                        return;
                    }
                    alert('获得访问令牌成功！点击确认，跳转回首页')
                    localStorage.setItem("ACCESS-TOKEN",resp.data.access_token);
                    localStorage.setItem("REFRESH-TOKEN",resp.data.refresh_token);

                    window.location.href = "/index.html"


                }
            })
        })
    </script>
</head>
<body>
登录成功
</body>
</html>